package demo1;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2022-07-05
 * Time: 23:05
 */
public class TestDemo {
    //实现杨辉三角
    public  static  List<List<Integer>>  generate  (int numRows){
        List<List<Integer>>   ret=new ArrayList<>();
        List<Integer>  list=new ArrayList<>();
        list.add(1);

        ret.add(list);
        for(int i=1;i<numRows;i++){
            List<Integer>   curROW=new ArrayList<>();
            curROW.add(1);//每一行第一个元素是1
            List<Integer>  prevRow=ret.get(i-1);
            for (int j=1;j<i;j++){
                int num= prevRow.get(j)+ prevRow.get(j-1);
                curROW.add(num);
            }
            curROW.add(1);//每一行最后一个元素是1
            ret.add(curROW);
        }
        return ret;

    }

    public static void main(String[] args) {
        List<List<Integer>> tmp=  generate(10);
        System.out.println(tmp);

    }

}
